/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;


import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Thanh Minh
 */
public class MySQLConnectionUtil {
    private  static MySQLConnectionUtil mysql;

    public String getUrl() {
        return url;
    }

    public String getUser() {
        return user;
    }

    public String getPass() {
        return pass;
    }

    public String getCharacterEncoding() {
        return CharacterEncoding;
    }

    public Connection getConnection() {
        return connection;
    }
    private String url;
    private String user;
    private String pass;
    private String CharacterEncoding;
    private Connection connection;
    //singleton patterm
    private MySQLConnectionUtil() throws SQLException{
    
        this.url="jdbc:mysql://localhost:3306/quanly_phongmach";
        this.user="root";
        this.pass="root";
        this.CharacterEncoding="utf8";
        Properties info = new Properties();
        info.setProperty("user", this.user);
        info.setProperty("password",this.pass);
        info.setProperty("characterEnconding",this.CharacterEncoding);
        DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
        this.connection=DriverManager.getConnection(url, info);
    }
    public static MySQLConnectionUtil getInstance() throws SQLException{
        if(mysql==null){
            mysql = new MySQLConnectionUtil();
        }
        return mysql;
    }
    public void close(){
        try {
           this.connection.close();
      } catch (SQLException ex) {
            System.out.println(ex);
      }
    }
}
